package com.dhq.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class sqlserverUtils {

	/**
	 * @param DatabaseName 数据库名   dhq
	 * @param userName  用户名  sa
	 * @param password  密码   123456
	 * @return Connection
	 */
	public static Connection getSqlServerConnection(String DatabaseName,
			String userName, String password) {
		String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

		// String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=你的数据库名";
		String dbURL = "jdbc:sqlserver://192.168.2.203:1433;DatabaseName="
				+ DatabaseName;

		try

		{

			Class.forName(driverName);

			Connection dbConn = DriverManager.getConnection(dbURL, userName,
					password);
			System.out.println(Thread.currentThread()+":连接数据库成功");
			return dbConn;

		}

		catch (Exception e)

		{

			e.printStackTrace();

			System.out.print("连接失败");

			return null;
		}
	}

	public static void realisSource(Connection connection, PreparedStatement prepareStatement) {
		try {
			prepareStatement.close();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
}
